/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mathma.discrete.set;

import mathma.core.value.Value;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;

/**
 * TODO -- make "final"
 *
 * @since 0.2.4
 * @author Ethan Levine
 */
public abstract class StaticSet<E extends Value> extends Set<E> {

    private final java.util.Set<E> set;

    public StaticSet(Collection items) {
        super(Set.Type.STATIC);
        set = Collections.unmodifiableSet(new HashSet<E>(items));
    }

    public java.util.Set<E> getBackingSet() {
        return set;
    }

    @Override
    public boolean isInfinite() {
        return false;
    }

    @Override
    public boolean isCountable() {
        return true;
    }

    @Override
    public boolean contains(E member) {
        return set.contains(member);
    }

    @Override
    public boolean isEqual(Set<E> other) {
        if (other.getSetType().equals(Set.Type.STATIC)) {
            boolean mismatch = false;
            for (E member : set) {
                if (!other.contains(member)) {
                    mismatch = true;
                }
            }
            for (E member : ((StaticSet<E>) other).getBackingSet()) {
                if (!contains(member)) {
                    mismatch = true;
                }
            }
            return !mismatch;
        }
        // TODO - finish implementation
        return false;
    }
}
